import os
import glob
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

y0 = []
name = []
for file_name in glob.glob(os.path.join(os.getcwd(), '*.txt')):
    with open(file_name, "r+") as readingfile:
        rows = readingfile.readlines()
        x = []
        y = []
        for row in rows:
            if '0' <= row[0] <= '9':
                m = row.strip('\n').strip('\t').strip('\t').split()
                x.append(m[0])
                y.append(m[1])
        newname = file_name.split('\\')[-1].strip('.txt')
        ylist = list(map(int, y))
        ymax = max(ylist)
        ymin = min(ylist)
        y0.append(y)
        name.append(newname)
        plt.figure(figsize=(22, 10))  # 设置画布为2200*1000像素
        plt.xticks([xt for xt in np.arange(0, 66, 5)])  # x轴刻度为1，长为66
        plt.yticks([yt for yt in range(ymin, ymax+10000, round((ymax - ymin)/15))])  # 自动坐标轴
        plt.plot(list(map(float, x)), ylist)
        plt.savefig(newname + '.jpg')
df = pd.DataFrame({})
df['x'] = x
for n in range(len(y0)):
    df[name[n]] = pd.Series(y0[n])
writer = pd.ExcelWriter('sepu' + '.xlsx')
df.T.to_excel(writer, newname, index=False)  # 只保存column而没有index
writer.save()
